﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ComponentModel.Composition;
using System.Diagnostics;
using System.ComponentModel;
using System.Collections.Generic;
using System.Windows.Data;
using System.IO;
using System.Linq;

using Cinch;
using MEFedMVVM.ViewModelLocator;
using MEFedMVVM.Services.Contracts;
using MEFedMVVM.Common;


namespace Anata.Client
{
    /// <summary>
    /// </summary>
    public class KonsumenFilterViewModel : ViewModelBase
    {
        #region Data
        
        #region Data.Primitives
        #endregion
        
        #region Data.Rules
        #endregion

        #region Data.VMs
        private DispatcherNotifiedObservableCollection<KonsumenViewModel> konsumens;
        private ICollectionView konsumensCV;
        #endregion

        #region Data.Services
        private IMessageBoxService messageBoxService;
        private IUIVisualizerService uiVisualizerService;
        #endregion

        #endregion

        #region Constructor
        [ImportingConstructor]
        public KonsumenFilterViewModel(
            IMessageBoxService messageBoxService,
            IUIVisualizerService uiVisualizerService)
        {
            #region Constructor.SetupServices
            this.messageBoxService = messageBoxService;
            this.uiVisualizerService = uiVisualizerService;
            #endregion

            #region Constructor.SetupCommands
            KonsumenSelectCommand = new SimpleCommand<Object, Object>(CanExecuteKonsumenSelectCommand, ExecuteKonsumenSelectCommand);
            #endregion

            #region Constructor.SetupDataWrappers
            #endregion

            #region Constructor.SetupValidationRules
            #endregion

            #region Constructor.SetupVMs
            Konsumens = new DispatcherNotifiedObservableCollection<KonsumenViewModel>();
            KonsumensCV = CollectionViewSource.GetDefaultView(konsumens);
            #endregion

            //debug use
            KonsumenViewModel kvm = null;
            for (int i = 1; i < 11; i++)
            {
                kvm = new KonsumenViewModel(
                    messageBoxService,
                    uiVisualizerService,
                    null,
                    null,
                    null);
                kvm.IdKonsumen.DataValue = i;
                kvm.Nama.DataValue = "Konsumen " + i;
                kvm.Alamat.DataValue = "Alamat " + i;
                kvm.Telepon.DataValue = "Telepon " + i;
                konsumens.Add(kvm);
            }
        }
        #endregion

        #region Public Properties

        #region Public.Commands
        public SimpleCommand<Object, Object> KonsumenSelectCommand { get; set; }
        #endregion

        #region Public.ViewMode
        #endregion

        #region Public.Data
        #endregion

        #region Public.CachedCollection
        #endregion

        #region Public.DataVM
        /// <summary>
        /// </summary>
        static PropertyChangedEventArgs konsumensChangeArgs =
            ObservableHelper.CreateArgs<KonsumenFilterViewModel>(x => x.Konsumens);
        public DispatcherNotifiedObservableCollection<KonsumenViewModel> Konsumens
        {
            get { return konsumens; }
            set
            {
                konsumens = value;
                NotifyPropertyChanged(konsumensChangeArgs);
            }
        }
        /// <summary>
        /// </summary>
        static PropertyChangedEventArgs konsumensCVChangeArgs =
            ObservableHelper.CreateArgs<KonsumenFilterViewModel>(x => x.KonsumensCV);
        public ICollectionView KonsumensCV
        {
            get { return konsumensCV; }
            set
            {
                konsumensCV = value;
                NotifyPropertyChanged(konsumensCVChangeArgs);
            }
        }
        #endregion

        #endregion

        #region Command Handlers
        private bool CanExecuteKonsumenSelectCommand(Object args)
        {
            return true;
        }
        /// <summary>
        /// </summary>
        private void ExecuteKonsumenSelectCommand(Object args)
        {
        }
        #endregion

        #region Private Methods
        //private void ViewAwareStatusService_ViewLoaded()
        //{
        //    konsumens = new DispatcherNotifiedObservableCollection<KonsumenViewModel>();
        //    KonsumenViewModel kvm = null;
        //    for (int i = 0; i < 10; i++)
        //    {
        //        kvm = new KonsumenViewModel();
        //        kvm.IdKonsumen.DataValue = i;
        //        kvm.Nama.DataValue = "Konsumen " + i;
        //        kvm.Alamat.DataValue = "Alamat " + i;
        //        konsumens.Add(new KonsumenViewModel());
        //    }
        //    //LoadedKonsumenCV = CollectionViewSource.GetDefaultView(loadedKonsumen);
        //}
        #endregion
    }

}
